package com.scu.bank.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.scu.bank.model.dao.FeedbackDao;
import com.scu.bank.model.example.FeedbackExample;
import com.scu.bank.model.pojo.AcademicActivitie;
import com.scu.bank.model.pojo.Feedback;
import com.scu.bank.model.base.BaseServiceImpl;
import com.scu.bank.model.pojo.ResearchProject;
import com.scu.bank.model.pojo.UserInfo;
import com.scu.bank.service.FeedbackService;
import com.scu.bank.service.ResearchProjectService;
import com.scu.bank.service.UserInfoService;
import com.scu.bank.util.ListUtils;
import com.scu.bank.util.StringGenerateUtil;
import com.scu.bank.util.WebUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * Created by pmeng on 2021/01/05.
 */
@Service
@Transactional
public class FeedbackServiceImpl extends BaseServiceImpl<Feedback,FeedbackDao> implements FeedbackService {
    @Autowired
    private FeedbackDao tSysFeedbackDao;
    @Autowired
    private UserInfoService userInfoService;
    @Autowired
    private ResearchProjectService researchProjectService;

    @Override
    public FeedbackDao getDao() {
        return tSysFeedbackDao;
    }

    @Override
    public PageInfo<Feedback> list(Integer page, Integer size) {
        PageHelper.startPage(page, size);
        FeedbackExample example = new FeedbackExample();
        example.createCriteria().andIsDelEqualTo(false);
        PageInfo pageInfo = new PageInfo(tSysFeedbackDao.selectByExample(example));

        List<Feedback> list = pageInfo.getList();
        if (!ListUtils.isEmpty(list)){
            list.forEach((temp)->{
                UserInfo userInfo = userInfoService.getById(temp.getCreateUser());
                temp.setCreateUserName(userInfo == null ? "无" : userInfo.getUserName());
                ResearchProject researchProject = researchProjectService.getById(temp.getPeoId());
                temp.setProName(researchProject == null ? "无" : researchProject.getProName());
            });
        }
        pageInfo.setList(list);
        return pageInfo;
    }

    @Override
    public void addFeedback(Feedback feedback) {
        save(feedback);
    }
}
